﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack.Redis;

namespace RedisDemo
{
    public static class RedisClientConfigurer
    {
        public static void RedisClientConfigure(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddTransient(typeof(RedisClient), p =>
            {
                string host = configuration.GetValue<string>("Redis:Host");
                int port = configuration.GetValue<int>("Redis:Port");
                string password = configuration.GetValue<string>("Redis:Password");
                long db = configuration.GetValue<long>("Redis:DB");

                var redisClient = new RedisClient(host, port, password, db);
                return redisClient;
            });
        }
    }
}
